package com.sx.controller;

import com.google.gson.Gson;
import com.sx.pojo.Goods;
import com.sx.service.GoodService;
import com.sx.service.serviceImpl.GoodServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
//商品详情
@WebServlet("/getGoodDetail")
public class GetGoodDetailServlet extends HttpServlet {
    private GoodService goodsService = new GoodServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String goodId = request.getParameter("id");
        Goods good = goodsService.getGoodById(goodId);
        Gson gson = new Gson();
        String json = gson.toJson(good);
        System.out.println(json);
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        PrintWriter out = response.getWriter();
        out.print(json);
        out.flush();
    }
}
